package com.gxa.controller;


import com.gxa.common.LayR;
import com.gxa.common.R;
import com.gxa.param.MyTableParam;
import com.gxa.pojo.Warn;
import com.gxa.service.CustomerCareWarnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/customer/care/warn")
public class CustomerCareWarnController {
    @Autowired
    private CustomerCareWarnService service;

    @GetMapping("/list/page")
    public String warnPage(){
        return "customer/customer-care-warn";
    }

    @PostMapping("/list/data")
    @ResponseBody
    public LayR listData(MyTableParam param){
        return service.list(param);
    }

    @PostMapping("/change/status")
    @ResponseBody
    public LayR  listData(Warn warn ){
        return service.updatestatus(warn);
    }


    @GetMapping("/add/page")
    public String addPage(){
        return "customer/customer-care-warn-add";
    }

    @RequestMapping("/add/do")
    @ResponseBody
    public R add(Warn warn){
        return service.add(warn);
    }

    @PostMapping("/edit/do")
    @ResponseBody
    public R edit(Warn warn, HttpSession session){
        Integer editWarnId = (Integer) session.getAttribute("editWarnId");
        warn.setWarnId(editWarnId);
        return service.edit(warn);
    }

    @GetMapping("/edit/page")
    public String editPage(Integer warnId, Model model, HttpSession session){
        session.setAttribute("editWarnId",warnId);
        model.addAttribute("warnId", warnId);
        return "customer/customer-care-warn-edit";
    }

    @PostMapping("/detail")
    @ResponseBody
    public R detail(Integer warnId){
        return service.findById(warnId);
    }

    @PostMapping("/delete")
    @ResponseBody
    public R delete(@RequestParam("ids[]") String[] ids){
        return service.deleteAll(ids);
    }

    @PostMapping("/deleteOne")
    @ResponseBody
    public R deleteOne(Integer warnId){

        return service.deleteOne(warnId);

    }


}
